package com.kxmall.web.controller.huishouapp;


import com.kxmall.common.annotation.Log;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.core.controller.BaseAppController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.page.TableDataInfo;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.huishou.domain.bo.HsSettlementOrderBo;
import com.kxmall.huishou.domain.bo.HsUserWasteBo;
import com.kxmall.huishou.domain.vo.HsSettlementOrderVo;
import com.kxmall.huishou.domain.vo.HsUserWasteVo;
import com.kxmall.huishou.service.IHsSettlementOrderService;
import com.kxmall.huishou.service.IHsUserWasteService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 回收结算订单信息
 *
 * @author kxmall
 * @date 2023-11-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/settlementOrder/app")
public class HsAppSettlementOrderController extends BaseAppController {

    private final IHsSettlementOrderService iHsSettlementOrderService;

    private final IHsUserWasteService iHsUserWasteService;


    /**
     * 查询回收结算订单信息列表
     */
//    @GetMapping("/list")
//    public TableDataInfo<HsSettlementOrderVo> list(HsSettlementOrderBo bo, PageQuery pageQuery) {
//        return iHsSettlementOrderService.queryPageList(bo, pageQuery);
//    }



    /**
     * 根据预约订单id获取结算订单信息
     *
     * @param appointOrderId
     */
    @GetMapping("/getSettleOrderBy/{appointOrderId}")
    public R<HsSettlementOrderVo> geOrderByAppointOrderId(@NotNull(message = "主键不能为空")
                                     @PathVariable Long appointOrderId) {
        HsSettlementOrderBo hsSettlementOrderBo = new HsSettlementOrderBo();
        hsSettlementOrderBo.setAppointOrderId(appointOrderId);
        hsSettlementOrderBo.setUserId(getAppLoginUser().getUserId());

        List<HsSettlementOrderVo> hsSettlementOrderVoList = iHsSettlementOrderService.queryList(hsSettlementOrderBo);
        HsSettlementOrderVo hsSettlementOrderVo = null;
        if(hsSettlementOrderVoList != null && hsSettlementOrderVoList.size()>0){
            hsSettlementOrderVo = hsSettlementOrderVoList.get(0);
        }

        if(hsSettlementOrderVo != null){
            HsUserWasteBo hsUserWasteBo = new HsUserWasteBo();
            hsUserWasteBo.setOrderId(hsSettlementOrderVo.getId());
            hsUserWasteBo.setOrderType(1L);
            List<HsUserWasteVo> hsUserWasteVoList = iHsUserWasteService.queryList(hsUserWasteBo);
            hsSettlementOrderVo.setHsUserWasteVoList(hsUserWasteVoList);
        }

        return R.ok(hsSettlementOrderVo);
    }

    /**
     * 获取回收结算订单信息详细信息
     *
     * @param id 主键
     */
//    @GetMapping("/{id}")
//    public R<HsSettlementOrderVo> getInfo(@NotNull(message = "主键不能为空")
//                                          @PathVariable Long id) {
//        HsSettlementOrderVo hsSettlementOrderVo = iHsSettlementOrderService.queryById(id);
//        if(hsSettlementOrderVo != null){
//            HsUserWasteBo hsUserWasteBo = new HsUserWasteBo();
//            hsUserWasteBo.setOrderId(id);
//            hsUserWasteBo.setOrderType(1L);
//            List<HsUserWasteVo> hsUserWasteVoList = iHsUserWasteService.queryList(hsUserWasteBo);
//            hsSettlementOrderVo.setHsUserWasteVoList(hsUserWasteVoList);
//        }
//
//        return R.ok(hsSettlementOrderVo);
//    }

    /**
     * 新增回收结算订单信息
     */
//    @Log(title = "回收结算订单信息", businessType = BusinessType.INSERT)
//    @RepeatSubmit()
//    @PostMapping()
//    public R<Void> add(@Validated(AddGroup.class) @RequestBody HsSettlementOrderBo bo) {
//        return toAjax(iHsSettlementOrderService.insertByBo(bo));
//    }

    /**
     * 修改回收结算订单信息
     */
//    @Log(title = "回收结算订单信息", businessType = BusinessType.UPDATE)
//    @RepeatSubmit()
//    @PutMapping()
//    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HsSettlementOrderBo bo) {
//        return toAjax(iHsSettlementOrderService.updateByBo(bo));
//    }

    /**
     * 删除回收结算订单信息
     *
     * @param ids 主键串
     */
//    @Log(title = "回收结算订单信息", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public R<Void> remove(@NotEmpty(message = "主键不能为空")
//                          @PathVariable Long[] ids) {
//        return toAjax(iHsSettlementOrderService.deleteWithValidByIds(Arrays.asList(ids), true));
//    }
}
